import { useWsStore } from '@/stores/module/ws'
import { useChatsStore } from '@/stores/module/chats/chats'

export function MesConnect() {
  // 在函数内部获取 store 实例
  const wsStore = useWsStore()
  const chatsStore = useChatsStore()

  if (wsStore.wsInstance == null) return

  wsStore.wsInstance.onmessage = (event) => {
    const wsMessage = JSON.parse(event.data)

    if (wsMessage.type == 4) {
      console.log(wsMessage.data)
    chatsStore.addMessage(wsMessage.data)
    }
  }
}
